package com.yulongtian.offers.day202211.day20221107;

/**
 * https://leetcode.cn/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof/?favorite=xb9nqhhg
 * 可
 * <p>
 * 记录二进制各个位的1的个数
 *
 * @author yulongTian
 * @create 2022-11-07 10:43
 */
public class Test02 {
    public static void main(String[] args) {
        int[] nums = {3, 4, 3, 3};
        int ints = singleNumber(nums);
        System.out.println(ints);
    }

    public static int singleNumber(int[] nums) {
        int len = nums.length;
        if (len == 1) {
            return nums[0];
        }
        int[] pos = new int[32];
        for (int i = 0; i < len; i++) {
            int temp = nums[i];
            for (int j = 0; j < 32; j++) {
                if (((temp >> j) & 1) == 1) {
                    pos[j]++;
                }
            }
        }
        int res = 0;
        for (int i = 0; i < 32; i++) {
            if (pos[i] % 3 != 0) {
                res += (1 << i);
            }
        }
        return res;
    }

}
